using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Grauers_set_metadata_properties.Grauers;
using System.Collections.Generic;

namespace Grauers_set_metadata_properties.Features.Grauers_set_metadata_properties
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("4571f2d8-8386-4c04-a127-e5d175906a1f")]
    public class Grauers_set_metadata_propertiesEventReceiver : SPFeatureReceiver
    {
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            List<DocumentPropertyItem> dpiList = DocumentPropertyBusinessLayer.GetAll();
            foreach (DocumentPropertyItem dpi in dpiList)
            {
                General.RemoveEventReceiver(dpi.Library);
            }
            if (SPContext.Current.Web.Properties["metadataPropertiesSettings"] != null)
            {
                SPWeb web = SPContext.Current.Web;
                web.AllowUnsafeUpdates = true;
                //web.AllProperties.Remove("metadataPropertiesSettings");
                //web.DeleteProperty("metadataPropertiesSettings");
                web.Properties["metadataPropertiesSettings"] = null;
                web.Properties.Update();
                web.Update();
                web.AllowUnsafeUpdates = false;
                //web.Update();
            }
        }     
    }
}
